package com.uphone.magicleafteacher.pro.adapter;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.blankj.utilcode.util.KeyboardUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.uphone.magicleafteacher.R;
import com.uphone.magicleafteacher.util.CommonUtil;
import com.uphone.magicleafteacher.view.MyBaseViewHolder;
import com.uphone.magicleafteacher.vo.ClassStudentBean;

import java.util.List;

public class CourseLiveStudentAdapter extends BaseQuickAdapter<ClassStudentBean.StuListBean, MyBaseViewHolder> {


    private final int liveStatus;
    int index = -1;

    public CourseLiveStudentAdapter(int layoutResId, @Nullable List<ClassStudentBean.StuListBean> data, int liveStatus) {
        super(layoutResId, data);
        this.liveStatus = liveStatus;
    }

    @Override
    protected void convert(@NonNull MyBaseViewHolder helper, ClassStudentBean.StuListBean item) {
        EditText etScore = helper.getView(R.id.et_score);
        if (liveStatus == 3) {//已打过积分
            etScore.setEnabled(false);
            etScore.setClickable(false);
            helper.setText(R.id.et_score, "积分" + CommonUtil.getStr(item.getJifen() + ""));
            etScore.setTextColor(mContext.getResources().getColor(R.color.red));
        } else {
            item.setJifen("");
            etScore.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    v.setFocusableInTouchMode(true);
                    v.requestFocus();
                    KeyboardUtils.showSoftInput(v);
                    return true;
                }
            });
            etScore.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable s) {
                    item.setJifen(s.toString() + "");
                }
            });
            etScore.clearFocus();
        }
        helper.setText(R.id.tv_name, CommonUtil.getStr(item.getStudentName()));
        helper.setText(R.id.tv_age, item.getAge() + "");
        if (item.getGender() == 1) {
            helper.setImageDrawable(R.id.img_x, mContext.getResources().getDrawable(R.drawable.ic_man));
        } else {
            helper.setImageDrawable(R.id.img_x, mContext.getResources().getDrawable(R.drawable.ic_woman));
        }
        Glide.with(mContext).load(CommonUtil.getImageUrl(item.getHeadPhoto())).apply(RequestOptions.bitmapTransform(new CircleCrop())).into((ImageView) helper.getView(R.id.iv_head));

    }

//    int index = -1;
//
//    public CourseLiveStudentAdapter() {
//        super(R.layout.item_course_live_student);
//    }
//
//    @Override
//    protected void convert(MyBaseViewHolder helper, Object item) {
//        EditText etScore = helper.getView(R.id.et_score);
//
//        etScore.setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//                v.setFocusableInTouchMode(true);
//                v.requestFocus();
//                KeyboardUtils.showSoftInput(v);
//                return true;
//            }
//        });
//        etScore.addTextChangedListener(new TextWatcher() {
//            @Override
//            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//
//            }
//
//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//
//            }
//
//            @Override
//            public void afterTextChanged(Editable s) {
//                notifyDataSetChanged();
//            }
//        });
//        etScore.clearFocus();
//
//
//
//    }
}
